package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.entity.dto.LearningPlanDTO;
import com.tianji.learning.entity.vo.LearningLessonVO;
import com.tianji.learning.entity.vo.LearningPlanPageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 学生课程表 控制器
 * </p>
 *
 * @author lemon
 */
@Api(tags = "我的课表相关接口") // 这个是用在类上的
@RestController
@RequiredArgsConstructor // 全参构造器并且会加入到spring容器中
@RequestMapping("/lessons")
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;

    /* 这个就是等价于上面的注解的 @RequiredArgsConstructor
    @Autowired
    public LearningLessonController(ILearningLessonService learningLessonService) {
        this.learningLessonService = learningLessonService;
    }
    */

    @ApiOperation(value = "分页查询我的课表") // 这个是用在方法上的
    @GetMapping("page")
    public PageDTO<LearningLessonVO> queryMyLesson(PageQuery query) {
        return learningLessonService.queryMyLesson(query);

    }


    @ApiOperation("删除用户选的课程")
    @DeleteMapping("{courseId}")
    public void deleteUserLesson(@PathVariable("courseId") Long courseId) {
        learningLessonService.deleteUserLesson(courseId);
    }

    // 注意这里我们只用查询一个因此返回的是一个对象
    @ApiOperation("查询正在学习的课程")
    @GetMapping("now")
    public LearningLessonVO queryNowLesson() {
        return learningLessonService.queryMyCurrentLesson();
    }


    // 创建学习计划
    @ApiOperation("创建学习计划")
    @PostMapping("plans")
    public void createLearningPlan(@RequestBody @Validated LearningPlanDTO dto) {
        learningLessonService.createLearningPlan(dto);

    }

    // 分页查询我的课程计划
    @ApiOperation("分页查询我的课程计划")
    @GetMapping("plans")
    public LearningPlanPageVO queryMyLearningPlan(PageQuery query) {
        return learningLessonService.queryMyLearningPlan(query);
    }
}
